// pages/info/info.js
const app = getApp()
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: { avatarUrl: '../img/moren.jpg' },
     date:'',
     welcome:'',
     realNmae:'',
    contact:'',
     settings:[
       {
         "icon": "../img/kefu.png",
         "name": "客服中心",
         "banbe": '暂未开放'
       },
       {
         "icon": "../img/suggestion.png",
         "name": "意见反馈",
         "tiao": '../img/right.png'
       },
       {
         "icon": "../img/banbe.png",
         "name": "版本号",
         "banbe": '1.0.1'
       }
       ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.globalData.userInfo)
    var DATE = util.formatDate(new Date());
    var time = new Date()
    var hour = time.getHours()
    console.log(hour)
    if (hour < 6) {
      this.setData({
        welcome: '凌晨好！'
      })}
    else if (hour < 9) {
      this.setData({
        welcome: '早上好！'
      })}
    else if (hour < 12) {
      this.setData({
        welcome: '上午好！'
      }) }
    else if (hour < 14) {
      this.setData({
        welcome: '中午好！'
      }) }
    else if (hour < 17) {
      this.setData({
        welcome: '下午好！'
      }) }
    else if (hour < 19) {
      this.setData({
        welcome: '傍晚好！'
      }) }
    else if (hour < 22) {
      this.setData({
        welcome: '晚上好！'
      }) }
    else {
      this.setData({
        welcome: '夜里好！'
      }) } 
    this.setData({
       userInfo : app.globalData.userInfo,
       realName: app.globalData.realName,
      contact: app.globalData.contact,
       date: DATE
    })
  },
  back:function(){
    wx.switchTab({
      url: '../person/person',
      success(res) {
        let page = getCurrentPages().pop();
        if (page == undefined || page == null) {
          return
        }
        page.onLoad();
      }
    })
  },
  /*formid 提交*/ 
  testSubmit: function (e) {
    let formId = e.detail.formId;
    // this.dealFormIds(formId); //处理保存推送码
    console.log(formId)
    let type = e.detail.target.dataset.type;
    var token = app.globalData.token
    console.log("our token is:" + token)
    wx.request({
      url: 'https://www.cycs023.cn/f50m-web/api/formids/',
      data: {
        formId: formId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'X-SDX-Token': token
      },
      success: function (res) {
        if (res.statusCode == 200) {
          console.log("提交成功")
        }
      }
    })
    //根据type的值来执行相应的点击事件
  },
  dealFormIds: function (formId) {
    let formIds = app.globalData.gloabalFomIds;//获取全局数据中的推送码gloabalFomIds数组
    if (!formIds) formIds = [];
    let data = {
      formId: formId,
      expire: parseInt(new Date().getTime() / 1000) + 604800 //计算7天后的过期时间时间戳
    }
    formIds.push(data);//将data添加到数组的末尾
    app.globalData.gloabalFomIds = formIds; //保存推送码并赋值给全局变量
  },
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})